var combinationSum2 = function (candidates, target) {
  let ans = []
  candidates.sort((a, b) => a - b)
  const dfs = (index, list, sum) => {
      if(sum===target) {
          ans.push(list)
          return 
      }
      if(sum > target) {
          return
      }
      for (var i = index; i < candidates.length; i++) {
          if(i>index&&candidates[i]===candidates[i-1]) {
              continue
          }
          if (candidates[i] <= target) {
              list.push(candidates[i])
              sum += candidates[i]
              dfs(i+1,[...list],sum)
              list.pop()
              sum -= candidates[i]
          }
      }
  }
  dfs(0,[],0)
  return ans
};
let nums = [2,5,2,1,2]
console.log(combinationSum2(nums,5));